package com.minhang.utils.result;

/**
 * 响应结果生成工具
 * @author dkj
 */
public class ResultGenerator {
    private static final String DEFAULT_SUCCESS_MESSAGE = "SUCCESS";

    /**
     * //只返回信息
     * @return
     */
    public static Result genSuccessResult() {
        return new Result()
                .setCode(ResultCode.SUCCESS)
                .setMessage(DEFAULT_SUCCESS_MESSAGE);
    }

    /**
     * //返回数据
     * @param data
     * @param <T>
     * @return
     */
    public static <T> Result<T> genSuccessResult(T data) {
        return new Result()
                .setCode(ResultCode.SUCCESS)
                .setMessage(DEFAULT_SUCCESS_MESSAGE)
                .setData(data);
    }
    public static <T> Result<T> genSuccessResult(String message,T data) {
        return new Result()
                .setCode(ResultCode.SUCCESS)
                .setMessage(message)
                .setData(data);
    }

    /**
     * //返回数据
     * @param data
     * @param <T>
     * @return
     */
    public static <T> Result<T> genSuccessResultFilePath(T data,String filePath) {
        return new Result()
                .setCode(ResultCode.SUCCESS)
                .setMessage(DEFAULT_SUCCESS_MESSAGE)
                .setData(data)
                .setFilePath(filePath);
    }

    /**
     * //返回数据加总数
     * @param data
     * @param count
     * @param <T>
     * @return
     */
    public static <T> Result<T> genSuccessListResult(T data, int count) {
        return new Result()
                .setCount(count)
                .setCode(ResultCode.SUCCESS)
                .setMessage(DEFAULT_SUCCESS_MESSAGE)
                .setData(data);
    }


    /**
     * //错误信息
     * @param message
     * @return
     */
    public static Result genFailResult(String message) {
        return new Result()
                .setCode(ResultCode.FAIL)
                .setMessage(message);
    }

    /**
     * //指定错误信息
     * @param message
     * @param code
     * @return
     */
    public static Result genFailResult(String message, ResultCode code) {
        return new Result().setCode(code).setMessage(message);
    }

    public static Result genFailResult(String message,int code){
        return new Result().setCode(code).setMessage(message);
    }

}
